package com.blog.common;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;


/**
 * Created by wy on 16/3/1.
 */
public class WebInterceptor implements Interceptor {

    @Override
    public void intercept(Invocation invocation) {
        try {
            // 设置菜单信息
            setMenu(invocation);

            invocation.invoke();

        } catch (Exception e) {
e.printStackTrace();
        }
    }

    public static void setMenu(Invocation invocation) {
        String actionKey = invocation.getActionKey();
        Controller controller = invocation.getController();
        String headerMenu = "";
        if (actionKey.contains("/blog/admin/content")) {
            headerMenu = "content";
        }else if (actionKey.contains("blog/admin/album")){
            headerMenu = "album";
        }else if (actionKey.contains("blog/admin/idea")){
            headerMenu = "idea";
        }else if (actionKey.contains("blog/admin/message")){
            headerMenu = "message";
        }
        controller.setAttr("headerMenu", headerMenu);
    }
}
